<template>
  <div id="vue2-app">
    <div id='public-links' @click="onRouteChange">
      <router-link to="/">Home</router-link> |
      <router-link to="/page2">Page2</router-link>
      <button @click="goto('appname-vue3', '/app-vue3')" style="margin:0 8px">to vue3 home</button>
      <button @click="goto('appname-vue3', '/app-vue3/page2')">to vue3 page</button>
    </div>
    <router-view />
  </div>
</template>

<script>
export default {
  name: 'App',
  methods: {
    // 子应用内部跳转时，通知侧边栏改变菜单状态
    onRouteChange () {
      if (window.__MICRO_APP_ENVIRONMENT__) {
        // 发送全局数据，通知侧边栏修改菜单展示
        window.microApp.setGlobalData({ name: window.__MICRO_APP_NAME__ })
      }
    },
    goto(appName, path){ //['appname-vue3', '/app-vue3']
        console.log('child vue2 goto :', appName, path)
        console.log(window.microApp.getData())
        window.microApp.getData().pushState(path)
         
        // window.microApp.router.setBaseAppRouter('/app-vue3')
        // window.microApp.router.push({ name: appName, path: path,})

    }
  }
}
</script>

<style>
#vue2-app {
  font-family: Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
}
</style>
